{* $Id$ *}
{include_core file="admin/lib/header.html" title="合伙人下单"}
<style>
  #js_upFile{
    position: absolute;
    top:0px;
    z-index: 20001;
    opacity: 0;
  }
  .js_editDiscount input{
    width:40px;
  }
  .cup_color {
    color: red;
  }

</style>
  <div class="page-header border-bottom clearfix">
    <h2 class="left">合伙人下单<span>在这里对合伙人进行下单</span></h2>
  </div>
  <div class="search-form js_advancedForm">
    <p>您还有<span class="cup_color js_box_sum">0</span>箱未配备杯子。</p>
  </div>
  <form action="{AnUrl('order/admin/trade/save_cup_data')}" method="post" class="js_trade_form">
    <table class="list-table" style="width:660px">
      <thead>
        <tr>
          <th style="width:160px;">杯型</th>
          <th style="width:100px;">每箱可装</th>
          <th style="width:60px;">设定箱数</th>
          <th style="width:100px;">应发/杯</th>
          <th style="width:100px;">实发/杯/件</th>
        </tr>
      </thead>
      <tbody class="js_cup_list">
      {foreach $cup_list as $k => $v}
        <tr class="js_cup_id_{$k}">
          <td>{$v}</td>
          <td>{$cup_data[$k]['box_cup_num']}杯</td>
          <td><input type="text" value="{$cup_data[$k]['box_num']}" name="cup_list[{$k}]" data-id="{$k}" class="js_cup_num"/></td>
          <td class="cup_num">{$cup_data[$k]['cup_num']}</td>
          <td class="true_num">{$cup_data[$k]['true_cup_num']}/{$cup_data[$k]['true_cup2box_num']}{if $k == 6}袋{else}件{/if}</td>
        </tr>
      {/foreach}
      </tbody>
      <tfoot>
        <tr>
            <td >
                <span style="color:red">*</span>备注：
            </td>
            <td colspan="10">
                <!-- 当前任务的备注 -->
                <textarea id="taskDesc"  name="task_desc" style="margin: 0px; width: 490px; height: 111px;" placeholder="请备注当前代理下单任务的指派人 订货人是哪位合伙人 或哪位公司同事的安排 账号信息 情况详细越好"></textarea>
            </td>
            
        </tr>
        <tr>
            <td >
                <span style="color:red">*</span>选择仓库：
            </td>
            <td colspan="10">
                {foreach $dealers_address_list as $v}
                 <p style="height:50px;"><input type="radio" name="dealer_address_id" {if $v.is_default} checked {/if} value="{$v.id}">
                 <span>收货人：{if $v.dealer_name}{$v.dealer_name}{else}暂无{/if}</span>
                 <span>收货人电话：{if $v.dealer_mobile}{$v.dealer_mobile}{else}暂无{/if}</span><br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>收货地址：{if $v.dealer_address} {$v.dealer_address} {else}暂无 {/if}</span></p>
                {/foreach}
            </td>
        </tr>
        <tr><td colspan="11"><button type="submit" class="btn btn-success btn-xs js_trade_order">提交订单</button></td></tr>
      </tfoot>
    </table>
  </form>
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
{load_js file='uploadify/jquery.uploadify.min.js'}
<script>

$(function(){
    var box_num = {$order_bulk_goods_num};
    var store_id = {$store_info.id}
    $('.js_cup_num').keyup(function(){
      autoNum($(this));
    });

    $('.js_cup_num').blur(function(){
      var cup_list = {  };
      var tmp_box_sum = 0;
      $('.js_cup_num').each(function(){
        var tmp_box_num = parseInt($(this).val());
        var tmp_box_key = $(this).data('id');
        tmp_box_sum = tmp_box_sum+tmp_box_num;
        cup_list[tmp_box_key] = tmp_box_num;
      });
      // 计算剩余数量
      var surplus_box_num = box_num - tmp_box_sum;
      if(surplus_box_num < 0) {
        showMsg('你配备的箱数已超额');
      }
      if ($.isNumeric(surplus_box_num)){
          $('.js_box_sum').html(surplus_box_num)
      } else {
          $('.js_box_sum').html('0')
      }
      //$('.js_box_sum').html(surplus_box_num);
      $.post(
          "{AnUrl('order/admin/trade/ajax_get_cup_data')}",
          { "cup_list":cup_list, 'store_id':store_id },
          function(data){
            if(data.info == 'ok') {
              $.each(data.data, function(i, n){
                $('.js_cup_id_'+i).find('.cup_num').html(n.cup_num);
                if (i == 6) {
                    showTitle = '袋';
                } else {
                    showTitle = '件';
                }
                $('.js_cup_id_'+i).find('.true_num').html(n.true_cup_num+'/'+n.true_cup2box_num + showTitle);
              });
            }
          }, 'json');
    });
    
    $('.js_trade_order').click(function(){
        var taskDesc = $('#taskDesc').val();
        if (taskDesc == '') {
            showMsg('请填写备注信息!', 2, 2);
            return false;
        }
        showMsg('正在提交中....', 1, 1);
    })

})
// 自动转为数字
function autoNum(obj) {
  var currNum = obj.val();
  currNum = parseInt(currNum);
  if (isNaN(currNum)) {
    currNum = 0;
  };
  obj.val(currNum);
}
function autoFloat(obj) {
  var currNum = obj.val();
  currNum = parseFloat(currNum);
  if (isNaN(currNum)) {
    currNum = 0;
  };
  obj.val(currNum.toFixed(2));
}
</script>
{include_core file="admin/lib/footer.html"}
